package kryptologieBlatt1;
import java.awt.AlphaComposite;

public class Aufgabe1 {

	private String plainAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	private String chiffreAlphabet = "EHVRDKXUJSA-CF-IWLTMNGPBZO";
	private String plainText = "";

	private String chiffre;

	public Aufgabe1() {
		translateChiffre();
		System.out.println(plainText);
	}

	private void translateChiffre() {
		int length = chiffre.length();
		String acc = "";
		for (int i = 0; i < length; i++) {
			String letter = chiffre.substring(i, i + 1);
			acc += translateLetter(letter);
		}
		plainText = acc;
	}

	private String translateLetter(String letter){
		String acc = "";
		int index = getLetterIndex(letter);
		acc = plainAlphabet.contains(letter) ? chiffreAlphabet.substring(index, index + 1) : letter;
		return acc;
	}

	private int getLetterIndex(String letter) {
		return letter.charAt(0) - 'A';
	}

	public static void main(String[] args) {
		String chiffre = "EAD FZMB PU APUAT DAJSKHDKUS KDXAPSAS JMBRKTWPV. QAUU "
				+ "AD APUAU JSKWAR WNKUUFHMBAU XKAMFS, JPUE KRRA HUSADJMBPAERPMB "
				+ "VDZJJ. EAD FARRUAD JZDSPADS JPA EKUU KHN EAT QAV "
				+ "YHT SPJMB EAJ VKJSAJ (JZEKJJ EAD FRAPUJSA KT JMBRHJJ ZXAU "
				+ "RPAVS, EAD UKAMBJSVDZAJJADA EKDHUSAD HUE EAD VDZAJJSA VKUY "
				+ "HUSAU). EKYH UPTTS AD TABDADA WNKUUFHMBAU CZU ZXAU HUE "
				+ "EDABS JPA HT HUE QPAEADBZRS EKJ (TPS IAQAPRJ HUSADJMBPAERPMB "
				+ "CPARAU WNKUUFHMBAU) JZ ZNS QPA UZASPV. QPA ZNS THJJ "
				+ "AD U WNKUUFHMBAU TKGPTKR QAUEAU, XPJ JPA JZDSPADS JPUE?";
		//new Aufgabe1();
		chiffre = chiffre.replace(" ", "");
		chiffre = chiffre.replace(",", "");
		chiffre = chiffre.replace(".", "");
		chiffre = chiffre.replace("?", "");
		chiffre = chiffre.replace("(", "");
		chiffre = chiffre.replace(")", "");
		Vigenere v = new Vigenere();
		v.drawFrequency(chiffre, 1000, 500);
	}

}
